home *** CD-ROM | disk | FTP | other *** search
/ The Fatted Calf / The Fatted Calf.iso / Applications / GraphicViewers / QuickViewer / Source / MyView.m < prev    next >
Text File  |  1992-08-25  |  3KB  |  126 lines

  1.  
  2. /* Generated by Interface Builder */
  3.  
  4. #import "MyView.h"
  5. #import <stdio.h>
  6. #import <appkit/NXImage.h>
  7. #import <3Dkit/N3DRIBImageRep.h>
  8. #import <objc/Object.h>
  9. #import <appkit/appkit.h>
  10. #import <appkit/OpenPanel.h>
  11. #import <dpsclient/wraps.h>
  12.  
  13. @implementation MyView
  14.  
  15. - initFrame:(const NXRect *)myFrame
  16. {
  17.     [super initFrame:myFrame];
  18.     [NXImage registerImageRep:[N3DRIBImageRep class]];
  19.     backgroundColor = NX_COLORWHITE;
  20.     return self;
  21. }
  22.  
  23. - readFile:sender
  24. {
  25.     id                  openPanel;
  26.     const char         *filename;
  27.     const char         *const types[5] = {"rib", "tiff", "eps", "ps", NULL};
  28.  
  29.     openPanel = [OpenPanel new];
  30.     [openPanel allowMultipleFiles:NO];
  31.     if ([openPanel runModalForTypes:types] &&
  32.         (theFile = filename = [openPanel filename])) {
  33.         if (filename) {
  34.             [self loadImage:filename];
  35.             [self display];
  36.             }
  37.     }
  38.     return self;
  39. }
  40.  
  41. - reloadImage:sender
  42. {
  43.  
  44.     if (theFile) {
  45.         if ([self loadImage:theFile])
  46.             [self display];
  47.         }
  48.     return self;
  49. }
  50.  
  51. - loadImage:(const char *)filename
  52. {
  53. //    NXPoint             imagePoint;
  54.  
  55.     if (filename) {
  56.         if (myImage){
  57. //            [myImageRep free];
  58.             [myImage free];
  59.         }
  60.     myImage = [[NXImage alloc] initFromFile:filename];
  61.     if (myImage) {
  62.         [QuickViewerWindow setTitleAsFilename:filename];
  63.         [myImage setScalable:YES];
  64.         [myImage getSize:&imageSize];
  65.  
  66.         myImageRep = [myImage bestRepresentation];
  67.         
  68. /* Special for RIB Images */
  69.         if ([[myImageRep class] instancesRespondTo:(SEL)@selector(setHider:)])
  70.         {
  71.             [myImageRep setSurfaceType:N3D_SmoothSolids];
  72.             [myImageRep setHider:N3D_HiddenRendering];
  73.         }
  74. /* End of special */
  75.  
  76. /* Cal center of Image
  77.         imagePoint.x = bounds.origin.x +
  78.         (bounds.size.width - imageSize.width) / 2.0;
  79.         imagePoint.y = bounds.origin.y +
  80.         (bounds.size.height - imageSize.height) / 2.0; */
  81.  
  82.     } else {
  83.         NXRunAlertPanel("Alert", "Error, cannot load image file.",
  84.         "OK", NULL, NULL);
  85.         return nil;
  86.         }
  87.     return self;
  88.     } else {
  89.         return nil;
  90.         }
  91. }
  92.  
  93.  
  94. - drawPS:(const NXRect *)rects :(int)rectCount
  95. {
  96.     NXSize    scaledSize;
  97.     NXPoint    factor;
  98.  
  99.     NXRectClip(rects);
  100.     NXSetColor(backgroundColor);
  101.     NXRectFill(&bounds);
  102.  
  103.     if (myImage) {
  104. /* Size to current view's size */
  105.     factor.x = bounds.size.width / imageSize.width;
  106.     factor.y = bounds.size.height / imageSize.height;
  107.     factor.x = factor.y = (factor.x < factor.y) ? factor.x : factor.y;
  108.     scaledSize = bounds.size;
  109.     scaledSize.width = imageSize.width * factor.x;
  110.      scaledSize.height = imageSize.height * factor.y;
  111.     [myImage setSize:&scaledSize];
  112.     [myImage composite:NX_COPY toPoint:&bounds.origin];
  113.     }
  114.     return self;
  115. }
  116.  
  117. - free
  118. {
  119.     [myImageRep free];
  120.     [myImage free];
  121.     [super free];
  122.     return self;
  123. }
  124.  
  125. @end
  126.